package edu.hrbu.spring.common;

import lombok.Builder;
import lombok.Data;

/**
 * @author 徐登宇
 */
@Data
@Builder
public class R {

    public static final int SUCCESS_CODE=0;
    public static final int ERROR_CODE=1;
    public static final String SUCCESS_MSG="操作成功";
    public static final String ERROR_MSG="操作失败";

    private int code; // 状态码
    private String message; // 附加信息
    private Object data; // 响应数据

    public static R success() {
        return R.builder().code(SUCCESS_CODE).message(SUCCESS_MSG).build();
    }

    public static R success(Object data) {
        return R.builder().code(SUCCESS_CODE).message(SUCCESS_MSG).data(data).build();
    }

    public static R error() {
        return R.builder().code(ERROR_CODE).message(ERROR_MSG).build();
    }

    public static R error(Object data) {
        return R.builder().code(ERROR_CODE).message(ERROR_MSG).data(data).build();
    }

}
